import {Service} from "adajs";
import {format} from "../../../lib/helper";

const MAP = ["局内转", "报人事局", "已批准", "已备案", "其他"];

class CourseService extends Service {
    defaultData() {
        return {
            list: [],
            map: null
        }
    }

    onupdate(current, {list}) {
        current.list = list;
        if (!current.map) {
            return this.context.request.get("/api/lgb/app/sys/sysDictionary/getByDictCode", {dictCode: "reason"}).then(a => {
                current.map = a.data;
                current.list = current.list.map(_item => {
                    let e = current.map.find(k => k.id === _item.reason);
                    return Object.assign({}, _item, {
                        state: e ? e.dictName : '其他',
                        time: _item.goDate ? format(new Date(_item.goDate.replace(/\-/g, "/")), 'yyyy-MM-dd') : '--'
                    });
                });
            });
        } else {
            current.list = current.list.map(_item => {
                let e = current.map.find(k => k.id === _item.reason);
                return Object.assign({}, _item, {
                    state: e ? e.dictName : '其他',
                    time: _item.goDate ? format(new Date(_item.goDate.replace(/\-/g, "/")), 'yyyy-MM-dd') : '--'
                });
            });
        }
    }
}

export default CourseService;